quietly{
version 16
	
*use "C:\Users\achen.POL-PF10YAEL\Documents\Word\citizen assemblies\Krashinsky project\BC data\bc 2009.dta"

* USE THIS ONE FOR LAPTOP
*cd "C:\Users\achen.POL-PF10YAEL\Documents\Word\citizen assemblies\Krashinsky project\BC data"

*THIS ONE IS FOR WORK DESKTOP
cd "C:\Users\achen\Documents\Word\citizen assemblies\Krashinsky project\BC data"

*IS THIS THE LOG FILE YOU WANT?
log using bc2009finalrun.txt, replace text

* incumbent Libs had won 46 to NDP's 33 in 2005. This survey is pre-election 2009.  
* Eventual 2009 votes were 45.8 Lib, 42.2 NDP, 8.2 Green, Tories 1.5, Indep 1.05,
* rest each < .5

gen weight = hhREGwgtw3
* Code intended 2009 referendum vote yes/no
clonevar choicereforig = V4
gen choiceref = choicereforig
replace choiceref = 1 if choicereforig == 5
replace choiceref = 0 if choicereforig == 1
replace choiceref = . if choicereforig>5
label define choiceref 0 "no" 1 "yes"
label values choiceref choiceref
*Next variable is intended provincial vote in 2009.
clonevar choiceprovorig = V2
gen choiceprov = choiceprovorig
* take out Greens and other (total of 20 resps) plus refused, etc.:
replace choiceprov = . if choiceprovorig>3
replace choiceprov = 4 if choiceprovorig==8
label define choiceprov 1 "Liberals" 2 "NDP" 3 "Greens" 4 "DK"
label values choiceprov choiceprov

gen libchoice = 0
replace libchoice = 1 if choiceprov==1
gen ndpchoice = 0
replace ndpchoice = 1 if choiceprov==2
gen greenchoice = 0
replace greenchoice = 1 if choiceprov==3
gen pcchoice = 0
replace pcchoice = 1 if V2==4

clonevar femaleorig = RGENDER
gen female = 0
replace female = 1 if femaleorig==5
replace female = . if femaleorig==.

*Correct answer on next one is yes=1; DK and refused coded as wrong answer throughout.
*Also respondents were not asked if they said they knew "nothing"--also coded as
*"no info" on each of the following:
*Correct answer on next one is yes=1; DK and refused coded as wrong answer throughout;
* some items correct = 5:
gen refinfo1 = 1
replace refinfo1 = 0 if A2 != 1
*Note error in codebook on codes for the following one:
gen refinfo2 = 0
replace refinfo2 = 1 if A3a == 2
replace refinfo2 = 1 if A3b == 1
gen refinfo3 = 1
replace refinfo3 = 0 if B2!=1
gen refinfo4 = 1
replace refinfo4 = 0 if B3!=5
gen refinfo5 = 1
replace refinfo5 = 0 if B5!=1
*Next one not included in BC 2005 survey:
gen refinfo6 = 1
replace refinfo6 = 0 if B8 !=1
*This one is in 2005 survey:
*"almost all" and "most" counted as true:
gen refinfo7 =1
replace refinfo7 = 0 if B9>2
gen refinfo = (refinfo1 + refinfo2 + refinfo3 + refinfo4 + refinfo5 + refinfo6 + refinfo7)/7
*This one is for comparison with 2005:
gen refinfocomp09 = refinfo1 + refinfo2 + refinfo3 + refinfo4 + refinfo5 + refinfo7
*Next one is for comparison with Ontario survey (almost identical questions):
gen refinfoshort = (refinfo1 + refinfo2 + refinfo3)/3

clonevar votereflikelyorig = V3
gen votereflikely = votereflikelyorig
*code DK, refused as very unlikely; need to reverse scale, too:
replace votereflikely = 4 if votereflikelyorig>4
replace votereflikely = 1 - (votereflikely - 1)/3
clonevar refinterestorig = D2
gen refinterest = refinterestorig
*code DK, refused as "no interest" in referendum:
replace refinterest = 0 if refinterestorig>10
replace refinterest = refinterest/10

/*
*Following two questions are in codebook but not in data.
*Party knowledge questions.  Here Libs are coded as anti, 
* NDP as pro:
gen libknow = 1
replace libknow = 0 if E1b != 5
gen ndpknow = 1
replace ndpknow = 0 if E2b != 1
* No parallel question about Greens
gen partyknow = (libknow+ndpknow)/2
*/

gen polinfo1 = 1
replace polinfo1 = 0 if F1 != 1
gen polinfo2 = 1
replace polinfo2 = 0 if F2 != 1
gen polinfo3 = 1
replace polinfo3 = 0 if F3 != 1
gen polinfo4 = 1
replace polinfo4 = 0 if F4 != 3
gen polinfo = (polinfo1 + polinfo2 + polinfo3 + polinfo4)/4

gen minorpolinfo = 0
replace minorpolinfo = polinfo*(ndpchoice+greenchoice)

*Now polinfo for Indep only. Has a neg (t=1) coeff if
* included in final probit:
gen indeppolinfo = 0
replace indeppolinfo = polinfo if libchoice == 0 & ndpchoice==0 & greenchoice==0

*Now pseudo-"know-party" variables because key vars missing here.
*However, worked poorly and are not used below:
gen libchoiceinfo = libchoice*polinfo
gen ndpchoiceinfo = ndpchoice*polinfo
gen greenchoiceinfo = greenchoice*polinfo

*Now some items about values and trust in Cit Assmb, with DK, refused = no:
gen promultiparty = 1
replace promultiparty = 0 if C1a!= 1 & C1b!=2
gen proproportionality = 1
replace proproportionality = 0 if C2!=5
gen prochoices = 1
replace prochoices = 0 if C5a !=2 & C5b!=1
gen proprefs = (promultiparty + proproportionality + prochoices)/3
gen trustcitassmb = 1
replace trustcitassmb = 0 if J1!=1

*Now therms in lieu of PIDs, which are missing from survey.
*DK, refused coded as 50 (midpoint):
gen libthermorig = H1
gen libtherm = libthermorig
replace libtherm = 50 if libthermorig > 100
replace libtherm = libtherm/100
gen ndpthermorig = H2
gen ndptherm = ndpthermorig
replace ndptherm = 50 if ndpthermorig > 100
replace ndptherm = ndptherm/100
gen greenthermorig = H3
gen greentherm = greenthermorig
replace greentherm = 50 if greenthermorig > 100
replace greentherm = greentherm/100
gen dob = DM1
gen age = 2009 - dob
replace age = . if dob>9990
*make age 0-1, corresponding to 18-100
replace age = (age-18)/82
gen educorig = DM2
gen educ = educorig
replace educ = . if educorig>10
replace educ = educ/10

gen incomeorig = DM11
gen income = incomeorig
replace income = 200 if incomeorig>200
replace income = . if incomeorig>997
gen incmissing = 0
replace incmissing = 1 if income==.
replace income = 0 if income==.
replace income = income/200

*Drop next section due to too much missing in incomesuppl
/* 
*copy in from supplemental income question
gen incomesuppl = DM11e
replace income = 10 if incomesuppl ==1
replace income = 30 if incomesuppl ==2
replace income = 50 if incomesuppl ==3
replace income = 70 if incomesuppl ==4
replace income = 90 if incomesuppl ==5
replace income = 110 if incomesuppl ==6
replace income = 135 if incomesuppl ==7
replace income = 200 if incomesuppl ==8
replace income = income/1000
*/

}
tab choiceref choiceprov [aweight=weight], col
tab choiceref refinfo [aweight=weight], col
*N's for previous tab:
tab choiceref refinfo, col
tab choiceref polinfo [aweight=weight], col
*Now N's for previous tab:
tab choiceref polinfo , col
tab choiceref proprefs [aweight=weight], col

tab trustcitassmb polinfo [aweight=weight] , col
bysort choiceprov: tab trustcitassmb polinfo [aweight=weight] , col

tab choiceref choiceprov [aweight=weight], col
tab choiceref choiceprov [aweight=weight] if polinfo==1, col

*No "party-know" questions on survey, also no PID questions, so:
probit choiceref educ age libchoice ndpchoice greenchoice   [pweight=weight]
fitstat

probit choiceref educ age i.libchoice i.ndpchoice i.greenchoice polinfo minorpolinfo [pweight=weight]
fitstat
margins, dydx(*) post

*Check income and gender:
probit choiceref educ age i.libchoice i.ndpchoice i.greenchoice polinfo minorpolinfo income i.incmissing i.female[pweight=weight]
fitstat
margins, dydx(*) post

* GRAPHS
graph bar (mean) choiceref [aweight = weight], over(choiceprov) ytitle(fraction yes) ti(British Columbia 2009)
graph export fig2.pdf,  logo(off) replace
graph save fig2, replace

*For line plot:
tab choiceref refinfocomp09 [aweight=weight], col
*N's for previous tab:
tab choiceref refinfocomp09, col

log close

